import { Body, Controller, Get, Head, Inject, Post, Req } from '@nestjs/common';
import { AppService } from './app.service';
import { UsersService } from './users/users.service';
import { CreateUserDto } from './users/dto/create-user.dto';
import { ApiBody, ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger';
import { User } from './users/entities/user.entity';
import { LoginUserDto } from './users/dto/login-user.dto';
import { Public } from './common/isPublic';
import { Request } from 'express';
import Constants from './common/constants';

@Controller()
@ApiTags('登录注册登出测试')
export class AppController {
  constructor(
    private readonly appService: AppService,
    private readonly usersService: UsersService,
    @Inject('Test') private readonly shop: string[],
  ) {}

  @Post('login')
  @Public()
  @ApiOperation({ summary: '登录' })
  login(@Body() loginUserDto: LoginUserDto) {
    return this.usersService.login(loginUserDto);
  }

  // @Post('register')
  // @Public()
  // @ApiOperation({ summary: '注册' })
  // register(@Body() createUserDto: CreateUserDto) {
  //   return this.usersService.register(createUserDto);
  // }

  @Post('logout')
  @Public()
  @ApiOperation({ summary: '登出' })
  logout(@Req() req: Request) {
    const token = req.headers[`${Constants.Access_Token}`] as string;
    return this.usersService.logout(token);
  }

  @Get('get')
  @Public()
  @ApiOperation({ summary: 'get测试' })
  get(): { msg: string } {
    return {
      msg: '成功通过get访问到后端',
    };
  }

  @Post('post')
  @Public()
  @ApiOperation({ summary: 'post' })
  post(@Body() postData: { data: string }): { msg: string } {
    return {
      msg: `成功通过post访问到后端,上传的数据为${postData.data}`,
    };
  }
}
